2016-07-18 183 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 >或者使用块 –

+0

@marco我不需要在xml.i到html插入xml.its已经存在需要获得通过HTML内容使用任何Java API。在我的问题中,我清楚地提到了我的输入和输出 –

+0

使用XML解析器通过XML标签提取XML信息。保持HTML。 –

回答

0

这很适合我

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

@约翰亚当 - 不要编辑你的问题的答案!不要打开新的问题复制粘贴上一个问题的答案!这不是如何表现对试图帮助你的人! - sharonb –

+0

这真的只是基本的礼貌,当你从别人复制粘贴else回答 –

0

你的主要问题在于

final String DIV_UNDER_ROOT = "/*/aoi"; 

这是一个XPath表达式,根据匹配“的任何节点2级根,它具有aoi的本地名称并且没有名称空间“。这不是你想要的。

你想匹配的是两层深的一个节点,其名称空间是由“苍井空”(这意味着它属于“http://www.aointl.com/20160331”命名空间),而其本地名称是“OtherIncomeAndExpensePolicyTextBlock”别名的任何内容。 XPath中使用Java

匹配的命名空间是安静的繁琐(见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工具​​和语法。就这些 –