2016-07-18 10 views
-2
<xbrli:xbrl xmlns:aoi="http://www.aointl.com/20160331" xmlns:country="http://xbrl.sec.gov/country/2016-01-31" xmlns:currency="http://xbrl.sec.gov/currency/2016-01-31" xmlns:dei="http://xbrl.sec.gov/dei/2014-01-31" xmlns:exch="http://xbrl.sec.gov/exch/2016-01-31" xmlns:invest="http://xbrl.sec.gov/invest/2013-01-31" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:naics="http://xbrl.sec.gov/naics/2011-01-31" xmlns:nonnum="http://www.xbrl.org/dtr/type/non-numeric" xmlns:num="http://www.xbrl.org/dtr/type/numeric" xmlns:ref="http://www.xbrl.org/2006/ref" xmlns:sic="http://xbrl.sec.gov/sic/2011-01-31" xmlns:stpr="http://xbrl.sec.gov/stpr/2011-01-31" xmlns:us-gaap="http://fasb.org/us-gaap/2016-01-31" xmlns:us-roles="http://fasb.org/us-roles/2016-01-31" xmlns:us-types="http://fasb.org/us-types/2016-01-31" xmlns:utreg="http://www.xbrl.org/2009/utr" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrldt="http://xbrl.org/2005/xbrldt" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <link:schemaRef xlink:href="aoi-20160331.xsd" xlink:type="simple"/> 
    <xbrli:context id="FD2016Q4YTD"> 
    <xbrli:entity> 
    <xbrli:identifier scheme="http://www.sec.gov/CIK">0000939930</xbrli:identifier> 
    </xbrli:entity> 
    <xbrli:period> 
    <xbrli:startDate>2015-04-01</xbrli:startDate> 
    <xbrli:endDate>2016-03-31</xbrli:endDate> 
    </xbrli:period> 
    </xbrli:context> 

    <aoi:OtherIncomeAndExpensePolicyTextBlock contextRef="FD2016Q4YTD" id="Fact-F51C7616E17E5B8B0B770D410BBF5A3E"> 
    <div style="font-family:Times New Roman;font-size:10pt;"><div style="line-height:120%;text-align:justify;font-size:10pt;"><font style="font-family:inherit;font-size:10pt;font-weight:bold;">Other Income (Expense)</font></div><div style="line-height:120%;text-align:justify;font-size:10pt;"><font style="font-family:inherit;font-size:10pt;"></font></div></div> 
    </aoi:OtherIncomeAndExpensePolicyTextBlock> 
    </xbrli:xbrl> 

This is My XML[XBRL], i need to parse this. This xml is my input and i don't know whether its a valid or not but in need output like this : 

    <div style="font-family:Times New Roman;font-size:10pt;"><div style="line-height:120%;text-align:justify;font-size:10pt;"><font style="font-family:inherit;font-size:10pt;font-weight:bold;">Other Income (Expense)</font></div><div style="line-height:120%;text-align:justify;font-size:10pt;"><font style="font-family:inherit;font-size:10pt;"></font></div></div> 

Please someone share me the knowledge for this problem i am facing from last two weeks. 

this is the code i am using 

    File fXmlFile = new File("/home/devteam-user1/Desktop/ky/UnitTesting.xml"); 
       DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 
       DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 
       Document doc = dBuilder.parse(fXmlFile); 

       XPath xPath = XPathFactory.newInstance().newXPath(); 
       final String DIV_UNDER_ROOT = "/*/aoi"; 
       NodeList divList = (NodeList)xPath.compile(DIV_UNDER_ROOT) 
         .evaluate(doc, XPathConstants.NODESET); 
       System.out.println(divList.getLength()); 
       for (int i = 0; i < divList.getLength() ; i++) { // just in case there is more than one 
        Node divNode = divList.item(i); 
        System.out.println(nodeToString(divNode)); 

//nodeToString method below 

    private static String nodeToString(Node node) throws Exception 
     { 
      Transformer transformer = TransformerFactory.newInstance().newTransformer(); 
      transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
      StreamResult result = new StreamResult(new StringWriter()); 
      transformer.transform(new DOMSource(node), result); 
      return result.getWriter().toString(); 
     } 
+0

私はよく分かりませんが、XMLをHTMLに組み込む必要がある場合は、その文字をエスケープする必要があります。例えばのHello Worldは<B>のHello World </B >または私がすることによって、そのHTMLコンテンツを取得するためにxml.i必要にすでに存在しxml.itsにHTMLを挿入する必要がいけないブロック –

+0

@marcoを使用するように出力されます任意のJava APIを使用します。私の質問で私は明確に私の入力と出力を言及しました –

+0

XMLパーサーを使用して、XMLタグでXML情報を抽出します。 HTMLを保存します。 –

答えて

0

あなたの主な問題は

の下に「任意のノード2つのレベルに一致するXPath式です
final String DIV_UNDER_ROOT = "/*/aoi"; 

である

public static void main(String[] args) throws IOException { 
    FileInputStream fis = new FileInputStream("yourfile.xml"); 
    Document doc = Jsoup.parse(Utils.streamToString(fis)); 
    System.out.println(doc.select("aoi|OtherIncomeAndExpensePolicyTextBlock").html().toString()); 
} 
+0

@sharonbn:私はここであなたのような巨人の知識人から知識を得ることを試みていることを願っています。うまく構成されていないXMLを教えてくれました。また、私の質問が適切であれば、私はこのフォーラムには新しいですが、私は解決策を簡単に得ることはできません。それ以外は何もしていません。ありがとうございます。 –

+0

@JohnAdam - あなたの質問への回答を編集しないでください!新しい質問を開いてはいけません。これは、あなたを助けようとしている人たちのために行動する方法ではありません! - sharonb –

+0

これは実際にあなたが誰かからコピー貼り付けをするときにクレジットを与えるだけの基本的な礼儀です。 –

0

これが私のためによく働きますroot、ローカル名はaoiで、名前空間はありません "。これはあなたが望むものではありません。

"aoi"(つまり、 "http://www.aointl.com/20160331"名前空間に属していて、その名前が "OtherIncomeAndExpensePolicyTextBlock"であることを意味します)によってエイリアスが付けられた2レベルの深さのノードのコンテンツに一致します。

JavaでのXPathで

マッチングの名前空間は静かな面倒(XPath with namespace in JavaHow to query XML using namespaces in Java with XPath?を参照)であるが、長い話を短く、あなたの代わりにこの方法を試みることができる:

final String DIV_UNDER_ROOT = "//*[local-name()='OtherIncomeAndExpensePolicyTextBlock' and namespace-uri()='http://www.aointl.com/20160331']/*"; 

あなたのDocumentBuilderFactoryが名前空間が認識されている場合にのみ動作します

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 
dbFactory.setNamespaceAware(true); 
+0

OPはXPATHツールと構文を使用するために時間を費やす必要があります。それはすべてです –

関連する問題